<!--
    功能待拆分为更细粒度的minxins，方便功能的组合使用
-->
<template>
    <div class="node-panel grid-panel">
        <div class="node-header">
            <Action-panel
                v-if="hasAction"
                :selectStatus="selectStatus"
                :model="model.actions"
            ></Action-panel>
                <Search-input
                    v-if="hasSearch"
                    @trigger="query"
                    :model="model"
					ref="search"
                ></Search-input>
        </div>
        <Grid-table
            class="node-content"
            @checkChange="checkChange"
            @actionTrigger="actionTrigger"
            ref="table"
            :loading="loading"
            :model="model"
            :hasCheck="hasCheck"
            :rowCheckMode="rowCheckMode"
            :data="tableData"
        >
            </Grid-table>
            <div class="table-page">
                <Page
                    :total="totalCount"
                    :current.sync="pageOn"
                    show-elevator
                    @on-change="fetch"
                ></Page>
            </div>
    </div>
</template>

<script>
import GridTable from '@/components/gridTableSample';
import SearchInput from '@/components/searchControl';
import Table from 'mixins/table';
import Action from 'mixins/action';
import $ from '@/common';
export default {
	mixins: [Table, Action],
	props: {
		model: {},
		hasCheck: {
			default: true,
		},
		rowCheckMode: {
			default: false,
		},
		hasSearch: {
			default: true,
		},
		hasAction: {
			default: true,
		},
	},
	data() {
		return {
			selectStatus: false,
		};
	},
	computed: {},
	methods: {
		//更新数据
		update() {
			this.fetch();
		},
		checkChange() {
			var table = this.$refs.table;
			if (table) {
				for (var i in table.checkList) {
					if (table.checkList[i]) {
						this.selectStatus = true;
						return;
					}
				}
			}
			this.selectStatus = false;
		},
		getSelectedIds() {
			var list = [];
			var table = this.$refs.table;
			if (table) {
				table.checkList.forEach((item, i) => {
					if (item) {
						var row = this.tableData[i];
						if (row) {
							list.push(row.id);
						}
					}
				});
			}
			return list;
		},
		getSelectedDataRow() {
			var table = this.$refs.table;
			for (var i in table.checkList) {
				if (table.checkList[i]) {
					return this.tableData[i];
				}
			}
		},
		//为table组件设置额外组件
		importTableComponents(data) {
			$.setProp(this.$options.components, data);
			this.$refs.table.importTableComponents(data);
		},
		//添加扩展渲染方法
		addExtRender(data) {
			this.$refs.table.addExtRender(data);
		},
	},
	components: {
		GridTable,
		SearchInput,
	},
};
</script>